<?php

include_once 'DB.php';

class Application_Model_Stat extends Application_Model_DB {

    public function addStatPage($page_id, $page_name, array $server, $ip) {
        $sql = "INSERT INTO `stat` SET
                    `page_id` = '".(int)$page_id."',
                    `page_name` = '".addslashes($page_name)."',
                    `referer` = '".  addslashes( !empty ($server["HTTP_REFERER"]) ? $server["HTTP_REFERER"] : '' )."',
                    `r_url` = '".  addslashes($server["REQUEST_URI"])."',
                    `user_ip` = '".  addslashes($ip)."',
                    `os` = '".  addslashes($server["HTTP_USER_AGENT"])."'
            ";
        return $this->Exec($sql);
    }

    public function getComments($page_id, $order = "DESC"){
        $sql =  "SELECT `name` , `comment`, `date_create`
                    From `stat`
                 WHERE `page_id` = " . (int)$page_id .
                 ' ORDER BY `date_create` ' . $order;
        return $this->GetAll($sql);
    }

}